<?php
class IndexController extends Forum_Controller_Action
{
    public function indexAction() 
    {
		$this->view->forumGroups = Forum::getSingleton('Forum_Group')->getList();
			if( !count($this->view->forumGroups) ){ $this->render(); return;}
	
			$res = Forum::getSingleton('Forum')->getList();
		    if( !count($res) ){ $this->render(); return;}
			$arrayForum = Array();
			for($i = 0; $i < count($res); $i++){
		        $arrayForum[$res[$i]['forum_group_id']][] = $res[$i];
		    }		
		$this->view->forum = $arrayForum;    		
		
			$res = Forum::getSingleton('Forum_Thread')->getListCount();
			if( !count($res) ){ $this->render(); return;}
			$arrayForumThreads = Array();
			for($i = 0; $i < count($res); $i++){
		        $arrayForumThreads[$res[$i]['forum_id']] = $res[$i]['count'];
		    }
		$this->view->ForumThreads = $arrayForumThreads;		
	
			$res = Forum::getSingleton('Forum_Message')->getListCountInForum();
			if( !count($res) ){ $this->render(); return;}
			$arrayForumMessages = Array();
			for($i = 0; $i < count($res); $i++){
		        $arrayForumMessages[$res[$i]['forum_id']] = $res[$i]['count'];
		    }
		$this->view->ForumMessages = $arrayForumMessages;			

			$res = Forum::getSingleton('Forum_Message')->getListLastInForum();
			if( !count($res) ){ $this->render(); return;}
			$arrayForumLastMessages = Array();
			for($i = 0; $i < count($res); $i++){
		        $arrayForumLastMessages[$res[$i]['forum_id']] = $res[$i];
				if($res[$i]['user_id'] != null){
					$arrayUserId[] = $res[$i]['user_id'];
				}
		    }
		$this->view->forumLastMessages = $arrayForumLastMessages;
			
			if( !isset($arrayUserId) ){ $this->render(); return;}
			$res = Forum::getSingleton('user')->getListById($arrayUserId);
			if( !count($res) ){ $this->render(); return;}
	        for($i = 0; $i < count($res); $i++){
	              $arrayUser[$res[$i]['id']] = $res[$i];
	        }
        $this->view->users = $arrayUser;

		$this->render();
    }
    
    
}
